package edu.neusoft.yiqibike.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import edu.neusoft.yiqibike.common.datasource.TargetDataSource;
import edu.neusoft.yiqibike.common.entity.mysql.OperationLog;
import edu.neusoft.yiqibike.dao.mapper.OperationLogMapper;
import edu.neusoft.yiqibike.service.IOperationLogService;
import org.springframework.stereotype.Service;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * User：lyc
 * Date：2017-12-17
 * Time：22:28
 * Description：
 */
@Service
public class OperationLogServiceImpl extends ServiceImpl<OperationLogMapper, OperationLog> implements IOperationLogService {

    @Override
    @TargetDataSource(name = "ds2")
    public Page<OperationLog> getLogByIP(Page<OperationLog> page, String ip) {
        List<OperationLog> logList = baseMapper.selectPageByIP(page, ip);
        logList = logList.stream().sorted(Comparator.comparing(OperationLog::getCreateTime).reversed()).collect(Collectors.toList());
        page.setRecords(logList);
        return page;
    }
}
